package com.example.zhxy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.zhxy.model.Student;
import com.example.zhxy.service.StudentService;
import com.example.zhxy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * ClassName: StudentController
 * Package: com.example.zhxy.controller
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-03-19
 * Time: 16:05
 */

@RestController
@RequestMapping("/sms/studentController")
public class StudentController {

    @Autowired
    private StudentService studentService;

    //GET
    //http://localhost:9001/sms/studentController/getStudentByOpr/1/3?name=好&clazzName=一年一班
    //学生管理的分页查询
    @GetMapping("/getStudentByOpr/{pageNo}/{pageSize}")
    public Result getStuPage(@PathVariable("pageNo") Integer pageNo,
                             @PathVariable("pageSize") Integer pageSize,
                             String name,String clazzName){
        //构造分页构造器
        Page<Student> page = new Page<>(pageNo,pageSize);

        //分页查询
        IPage<Student> iPage = studentService.stuPage(page,name,clazzName);

        return Result.ok(iPage);

    }


    //POST
    //	http://localhost:9001/sms/studentController/addOrUpdateStudent
    //学生管理的 新增和修改
    @PostMapping("/addOrUpdateStudent")
    public Result addAndUpdate(@RequestBody Student student){
        //调用服务层

        studentService.saveOrUpdate(student);

        return Result.ok();


    }

}
